const mongoose = require('mongoose')

/**
 * 企业家信息模型
 * - entrepreneurId: 企业家记录ID
 * - joinDate: 入班时间
 * - files: 关联图片文件
 * - name: 企业家姓名
 * - company: 公司名称
 * - position: 职位
 * - industry: 所属行业
 * - business: 主营业务
 * - connections: 想结交的人脉
 * - resources: 想获得的资源
 * - projects: 项目介绍
 */
const EntrepreneurSchema = new mongoose.Schema(
  {
    entrepreneurId: {
      type: String,
      required: true,
      default: function () {
        return this._id.toString()
      }
    },
    joinDate: {
      type: Date,
      required: true,
      get: v => v.toISOString().split('T')[0] // 格式化输出为YYYY-MM-DD
    },
    files: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'File',
      required: true
    },
    name: {
      type: String,
      required: true,
      maxlength: 50
    },
    company: {
      type: String,
      required: true,
      maxlength: 100
    },
    position: {
      type: String,
      required: true,
      maxlength: 50
    },
    industry: {
      type: String,
      required: true,
      maxlength: 50
    },
    business: {
      type: String,
      required: true,
      maxlength: 1000
    },
    connections: {
      type: String,
      required: true,
      maxlength: 1000
    },
    resources: {
      type: String,
      required: true,
      maxlength: 1000
    },
    projects: {
      type: String,
      required: true,
      maxlength: 2000
    },
    createdAt: {
      type: Date,
      default: Date.now
    }
  },
  { timestamps: true }
)

EntrepreneurSchema.set('toJSON', { getters: true })
EntrepreneurSchema.index({ year: 1, entrepreneurId: 1 })

module.exports = mongoose.model('Entrepreneur', EntrepreneurSchema)
